package com.zhang.yygh.hosp.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.yygh.model.hosp.Schedule;
import com.zhang.yygh.common.result.R;
import com.zhang.yygh.hosp.repository.ScheduleRepository;
import com.zhang.yygh.hosp.service.ScheduleService;
import com.zhang.yygh.hosp.utils.HttpRequestHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp")
public class ApiScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    //排班删除
    @PostMapping("/schedule/remove")
    public R remove(HttpServletRequest httpServletRequest){
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(httpServletRequest.getParameterMap());
        scheduleService.remove(paramMap);
        return R.ok().code(200);
    }

    //排班分页
    @PostMapping("/schedule/list")
    public R getSchedulePage(HttpServletRequest httpServletRequest){
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(httpServletRequest.getParameterMap());
        Page page=scheduleService.getSchedulePage(paramMap);
        Map map = JSONObject.parseObject(JSONObject.toJSONString(page), Map.class);
        return R.ok().code(200).data(map);
    }

    //排班信息保存
    @PostMapping("/saveSchedule")
    public R saveSchedule(HttpServletRequest httpServletRequest){
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(httpServletRequest.getParameterMap());
        scheduleService.saveSchedule(paramMap);
        return R.ok().code(200);
    }
}
